//
//  YZDoctorConditionView.m
//  患者信息界面（代码）
//
//  Created by Yip-Jun on 16/5/9.
//  Copyright © 2016年 YIPWJ. All rights reserved.
//

#import "YZDoctorConditionView.h"
#import "Masonry.h"

@interface YZDoctorConditionView ()

@property (nonatomic, strong) UIView *grayView;
@property (nonatomic, strong) UIImageView *sickerImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *openButton;

@property (nonatomic, strong) UILabel *bisicLabel;
@property (nonatomic, strong) UILabel *sickDescribeLabel;
@property (nonatomic, strong) UILabel *medicalLabel;

@end

@implementation YZDoctorConditionView

+ (instancetype)doctorConditionView {
    YZDoctorConditionView *doctorView = [[YZDoctorConditionView alloc] init];

    [doctorView prepareUI];
    [doctorView setSubviewsFrame];
    
    return doctorView;
}

- (void)prepareUI {
 
    [self addSubview:self.grayView];
    [self.grayView addSubview:self.sickerImageView];
    [self.grayView addSubview:self.titleLabel];
    [self.grayView addSubview:self.openButton];
    
    [self addSubview:self.bisicLabel];
    [self addSubview:self.sickDescribeLabel];
    [self addSubview:self.medicalLabel];
}

- (void)setSubviewsFrame {
    
    [self.grayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.top.equalTo(self);
        make.height.mas_equalTo(30);
    }];
    
    [self.sickerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.grayView);
        make.leading.mas_equalTo(16);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.grayView);
        make.leading.equalTo(self.sickerImageView.mas_trailing).offset(16);
    }];

    [self.openButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.titleLabel);
        make.trailing.equalTo(self).offset(-8);
    }];
    
    [self.bisicLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.grayView.mas_bottom).offset(8);
        make.leading.equalTo(self).offset(16);
    }];
    
    [self.sickDescribeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bisicLabel);
        make.leading.equalTo(self.bisicLabel.mas_trailing).offset(8);
    }];
    
    [self.medicalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self).offset(-8);
        make.leading.equalTo(self.sickDescribeLabel);
    }];
}

- (void)openButtonDidClick: (UIButton *)button {
    button.selected = !button.selected;
    self.bisicLabel.hidden = !self.bisicLabel.hidden;
    self.sickDescribeLabel.hidden = !self.sickDescribeLabel.hidden;
    self.medicalLabel.hidden = !self.medicalLabel.hidden;
    if (button.selected) {
        button.backgroundColor = [UIColor colorWithRed:(0 / 255.0) green:(122 / 255.0) blue:(255 / 255.0) alpha:1];
        button.layer.cornerRadius = 5;
        UIColor *selectBackgroundColor = [UIColor lightGrayColor];
        [button setTitleColor:selectBackgroundColor forState: UIControlStateSelected];
    } else {
        button.backgroundColor = [UIColor clearColor];
        [button setTitleColor: [UIColor colorWithRed:(0 / 255.0) green:(122 / 255.0) blue:(255 / 255.0) alpha:1] forState: UIControlStateNormal];
    }
    self.opneButtonDidClickBlock();
}

#pragma mark - 懒加载
- (UIView *)grayView {
    if (!_grayView) {
        _grayView = [[UIView alloc] init];
        _grayView.backgroundColor = [UIColor lightGrayColor];
    }
    return _grayView;
}

- (UIImageView *)sickerImageView {
    if (!_sickerImageView) {
        _sickerImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"product_img_icon_xieyi.png"]];
    }
    return _sickerImageView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.text = @"医生条件";
    }
    return _titleLabel;
}

- (UIButton *)openButton {
    if (!_openButton) {
        _openButton = [[UIButton alloc] init];
        _openButton.titleLabel.font = [UIFont systemFontOfSize:16];
        _openButton.contentEdgeInsets = UIEdgeInsetsMake(2, 5, 2, 5);
        [_openButton addTarget:self action:@selector(openButtonDidClick:) forControlEvents: UIControlEventTouchUpInside];
        [_openButton setTitle:@"展开" forState: UIControlStateNormal];
        [_openButton setTitle:@"收起" forState: UIControlStateSelected];
        [_openButton setTitleColor: [UIColor colorWithRed:(0 / 255.0) green:(122 / 255.0) blue:(255 / 255.0) alpha:1] forState: UIControlStateNormal];
    }
    return _openButton;
}

- (UILabel *)bisicLabel {
    if (!_bisicLabel) {
        _bisicLabel = [[UILabel alloc] init];
        _bisicLabel.text = @"基本条件：";
        _bisicLabel.font = [UIFont systemFontOfSize:16];
        _bisicLabel.textColor = [UIColor colorWithRed:(0 / 255.0) green:(122 / 255.0) blue:(255 / 255.0) alpha:1];
    }
    return _bisicLabel;
}

- (UILabel *)sickDescribeLabel {
    if (!_sickDescribeLabel) {
        _sickDescribeLabel = [[UILabel alloc] init];
        _sickDescribeLabel.text = @"需要提供疾病描述";
        _sickDescribeLabel.font = [UIFont systemFontOfSize:16];
    }
    return _sickDescribeLabel;
}

- (UILabel *)medicalLabel {
    if (!_medicalLabel) {
        _medicalLabel = [[UILabel alloc] init];
        _medicalLabel.text = @"需要提供病例";
        _medicalLabel.font = [UIFont systemFontOfSize:16];
    }
    return _medicalLabel;
}

//@property (nonatomic, strong) UILabel *bisicLabel;
//@property (nonatomic, strong) UILabel *sickDescribe;
//@property (nonatomic, strong) UILabel *medicalLabel;



@end
